package com.qianfeng.freeshiro.util;

import com.jagregory.shiro.freemarker.ShiroTags;
import freemarker.template.TemplateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import java.io.IOException;
import java.util.Properties;

@Component
public class FreeMarkerConfigExtend extends FreeMarkerConfigurer {
    @Autowired
    protected org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver resolver;

    @Override
    public void afterPropertiesSet() throws IOException, TemplateException {
        resolver.setSuffix(".ftl");
        resolver.setCache(false);
        super.afterPropertiesSet();
        this.getConfiguration().setSharedVariable("shiro", new ShiroTags());
    }

    public FreeMarkerConfigExtend(){
        super();
        this.setTemplateLoaderPaths("classpath:templates/");
        this.setDefaultEncoding("utf-8");
        Properties prop = new Properties();
        prop.setProperty("template_update_delay", "0");
        prop.setProperty("locale", "zh_CN");
        prop.setProperty("default_encoding", "utf-8");
        this.setFreemarkerSettings(prop);
    }
}
